package com.link.base.base.common.service;

import com.link.base.base.common.dao.mybatis.mapper.UserProtocolMapper;
import com.link.base.base.common.model.UserProtocol;
import com.link.core.basic.service.ServiceException;
import com.link.core.cllog.LCLogger;
import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * Copyright  hande Company. All Rights Reserved.
 *
 * @author  unknwon
 * @date:   2018/11/9 10:24
 * @version 1.0
 */

@Service
@Transactional(rollbackFor = ServiceException.class)
public class UserProtocolServiceImpl implements UserProtocolService {

    @Resource
    private UserProtocolMapper userProtocolMapper;

    /**
     *  通过登录名查询用户是否接受协议，将查询结果封装在Bean里面
     * @param loginName
     * @return
     * @throws ServiceException
     */
    @Override
    public UserProtocol queryProtocolStatusByLoginName(String loginName)
            throws ServiceException {
        UserProtocol result = null;
        try {
            result = userProtocolMapper.queryProtocolStatusByLoginName(loginName);
        } catch (Exception e) {
            LCLogger.withException(e);
            throw new ServiceException(e.getMessage());
        }
        return result;
    }

    /**
     * 向用户协议表插入数据，不拼接用户信息
     * @param record
     * @throws ServiceException
     */
    @Override
    public void insertUserProtocol(UserProtocol record)
            throws ServiceException {
        try {
            userProtocolMapper.insertUserProtocol(record);
        } catch (Exception e) {
            LCLogger.withException(e);
            throw new ServiceException(e.getMessage());
        }

    }

    /**
     * 查询用户名是否存在，存在返回UserProtocl对象并并把用户名存进去
     * @param loginName
     * @return
     * @throws ServiceException
     */
    @Override
    public UserProtocol queryUserNameExist(String loginName) throws ServiceException {
        UserProtocol result = null;
        try {
            result = userProtocolMapper.queryUserNameExist(loginName);
        } catch (Exception e) {
            LCLogger.withException(e);
            throw new ServiceException(e.getMessage());
        }
        return result;
    }


}
